.org 0xC3A50 ; Double Terrain Stars 

Double_Terrain_Stars:

	PUSH 	{R4, LR}
	
	CMP 	R1, Unit_None						; Is there a Unit on the Terrain?
	BEQ		No_Unit_On_Terrain
	
	MOV		R3, 0x6C
	MUL		R3, R1, R3
	LDR		R1, [Double_Stars_1]
	LDRB	R1, [R1, R3]
	
	CMP		R1, Deployed_Airport 				; It checks if the unit is built from an Airport
	MOVEQ	R0, 0								; If unit is built from an Airport, no Terrain Firepower
												
	POPEQ 	{R4, LR}
	BXEQ	LR
	
No_Unit_On_Terrain:	
	
	LDR 	R3, [Double_Stars_2]
	LDR 	R1, [Double_Stars_3]	
	LDR 	R12, [R3, 0]
	LDR 	R3, [R1, 0]	
	MOV 	R1, 0x18		
	ADD 	R3, R12, R3, LSL 2
	LDR		R12, [R3, 0x48]
	MUL		R3, R2, R1
	ADD 	R1, R12, 0x5000
	LDR 	R12, [R1, 0xA58]
	MOV 	R1, 0x98
	MLA		R12, R0, R1, R12
	LDR 	R2, [Double_Stars_4]
	
	MOV		R0, 10								; Firepower per Star
	LDR 	R1, [R2, R3]						; R1 = # Terrain Stars	
	MUL		R0, R1, R0							; R0 = # Terrain Stars x Firepower per Star
	
	LDRSB	R1, [R12, 0x2A]
	ADDS	R4, R1, R0
	MOVMI	R0, 0
	
	POPMI 	{R4, LR}
	BXMI	LR
	
	ADD		R0, R12, 0x74
	
	MOV 	R1, CO_Double_Terrain				; Skill: Double Terrain Stars
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?	
	ADDNE	R4, R4, R4							; If CO use skill, double the terrain stars
	
	MOV		R0, R4
	
	POP		{R4, LR}	
	BX 		LR

;-------------------------------------------------------------------------------		

Double_Stars_1:
	.dw 0x022F4FD7

Double_Stars_2:
	.dw Reg1_Skill
	
Double_Stars_3:
	.dw Reg2_Skill
	
Double_Stars_4:
	.dw 0x022F4CCC



